home *** CD-ROM | disk | FTP | other *** search
- Path: newsfeed.gsfc.nasa.gov!usenet
- From: John Hannon <hannon>
- Newsgroups: comp.lang.c
- Subject: Re: What is '?' in C mean....?????
- Date: 9 Jan 1996 13:41:37 GMT
- Organization: NASA Goddard Space Flight Center -- Greenbelt, Maryland USA
- Message-ID: <4ctrah$aoc@post.gsfc.nasa.gov>
- References: <4cgsa8$bm2@wumpus.cc.uow.edu.au> <fcusack-0401961115540001@mudskipper.cac.psu.edu> <4ci5bb$8m4@www.gnofn.org>
- NNTP-Posting-Host: acrobat.gsfc.nasa.gov
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.1N (X11; I; IRIX 5.3 IP12)
- X-URL: news:4ci5bb$8m4@www.gnofn.org
-
- clm01@www.gnofn.org (Christopher L Mayeux) wrote:
- > frank. (fcusack@tdx.org) wrote:
- >: > Could anyone here explain to me what is "?" means and what the purpose
- >: of using
- >:
- >: ? : is C's ternary operator. if the condition is met, perform the
- >: operation after the ?; if the condition is not met, perform the operation
- >: after the :
- >:
- >
- >What new perversion of C is that ???
- >
- >I've been programming in standard C for 12 years, and
- >never saw THAT in the manuals.
- >--
- >------------------------------------------------------------------------------
- >C.L. Mayeux - Owner, MSB Video <clm01@gnofn.org> - Affordable consumer videos.
-
-
- In K & R II, p. 51:
-
- ". . . the ternary operator "?:" provides an alternate way . . .
- In the expression
-
- expr1 ? expr2 : expr3
-
- the expression expr1 is evaluated first. If it is non-zero (true), then the
- expression expr2 is evaluated, and that is the value. Otherwise expr3 is
- evaluated, and that is the value. Only one of expr2 and expr3 is evaluated.
- Thus to set z to the maximum of a and b,
-
- z = (a > b) ? a : b; /* z = max(a,b) */
- --
- _____________________________________
- |John Hannon |
- |General Sciences Corp 301-352-2123 |
- |MODIS Characterization Support Team |
- |hannon@acrobat.gsfc.nasa.gov |
- |____________________________________|
-
-